<?
	if($_GET) {
		@require_once(str_replace('ajax','',dirname(__FILE__)) . "functions.php");
		$offset = drizzo_global_options('timezone_offset');
		$timestamp = gmmktime($_GET['current_hour'],$_GET['current_min'],00,$_GET['month'],$_GET['current_day'],$_GET['current_year']);
		for($i = 8; $i < 15; $i++) { // Get the start of DST for the year of the timestamp
			if(gmdate('w',gmmktime(2 + $offset,0,0,3,$i,gmdate('Y',$timestamp))) == 0) {
				$dst_start = gmmktime(2 + $offset,0,0,3,$i,gmdate('Y',$timestamp));
			}
		}
		for($i = 25; $i < 32; $i++) { // Get the end of DST for the year of the timestamp
			if(gmdate('w',gmmktime(2 + $offset,0,0,11,$i,gmdate('Y',$timestamp))) == 0) {
				$dst_end = gmmktime(2 + $offset,0,0,11,$i,gmdate('Y',$timestamp));
			}
		}
		if($dst_start <= $timestamp && $timestamp <= $dst_end) { // If the timestamp is in DST adjust the offset
			$offset++;
			$_GET['current_hour']++;
		}
		$dropdowns .= "<select name=\"" . $_GET['name_prefix'] . "date_hour\" id=\"" . $_GET['name_prefix'] . "date_hour_dropdown\" class=\"date_select\">";
		$midnight = gmdate('G', gmmktime($offset, gmdate('i'), gmdate('s'), gmdate('m'), gmdate('d'), gmdate('Y')));
		for($i = 0; $i < 24 ; $i++) {
			$i = str_pad($i,2,'0',STR_PAD_LEFT);
			$h = gmdate('G', gmmktime($i + $offset, gmdate('i'), gmdate('s'), gmdate('m'), gmdate('d'), gmdate('Y')));
			if($h >= $midnight) {
				$hours[$h] = ($i + 24);
			} else {
				$hours[$h] = ($i);
			}
		}
		ksort($hours);
		foreach($hours as $key => $val) {
			if($key == 0) {
				$key = 12;
			} elseif($key > 12) {
				$key = $key - 12;
			}
			if($val == $_GET['current_hour']) {
				$dropdowns .= "<option value =\"$val\" selected>$key</option>";
			} else {
				$dropdowns .= "<option value =\"$val\">$key</option>";
			}
		}
		$dropdowns .= "</select></span>\n";
		echo $dropdowns;
	}
?>